package com.mp.demo.common;

import lombok.Data;

import javax.servlet.http.HttpServletResponse;

@Data
public class Result {


    int code = 2001;

    int httpCode = HttpServletResponse.SC_OK;

    String msg="success";

    Object data;

    public Result() {
    }

    public Result(int code, int httpCode, String msg, Object data) {
        this.code = code;
        this.httpCode = httpCode;
        this.msg = msg;
        this.data = data;
    }

    public static Result defaultMsg(boolean flag) {
        if (flag){
            return success("success",null);
        }
        return err("error");
    }

    public static Result success(String msg,Object data) {
        Result result = new Result();
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setData(data);
        return result;
    }

    public static Result err(String msg) {
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(4001);
        return result;
    }

    public static Result err(int code,String msg) {
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(code);
        return result;
    }

}
